package cn.tedu.csmailproduct.controller;

import cn.tedu.csmailproduct.ex.ServiceException;
import cn.tedu.csmailproduct.pojo.dto.AlbumAddNewDTO;
import cn.tedu.csmailproduct.service.IAlbumService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 处理相册相关请求的控制器
 *
 * @author java@qq.com
 * @version 0.0.1
 *
 */

@Api(tags = "01. 相册管理模块")
@Slf4j
@RestController
@RequestMapping("/albums")
public class AlbumController {

    @Autowired
    private IAlbumService albumService;

    public AlbumController(){
        log.debug("创建控制器对象：AlbumController");
    }

    // http://localhost:8080/add-new?name=相册001&description=相册001的简介&sort=199
    @ApiOperation("添加相册")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public String addNew(AlbumAddNewDTO albumAddNewDTO){
        log.debug("开始处理【添加相册】的请求，参数：{}：",albumAddNewDTO);
        albumService.addNew(albumAddNewDTO);
        log.debug("添加数据成功");
        return "添加相册成功！";
    }

//    @ApiImplicitParam(name = "id",value = "相册id",required = true,dataType = "long")
    @ApiOperation("删除相册")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id",value = "相册id",required = true,dataType = "long"),
        @ApiImplicitParam(name = "name",value = "相册名称",required = true,dataType = "string")
    })
    @PostMapping("/{id:[0-9]+}/delete")
    public String delete(@PathVariable Long id,String name){
        String message = "尝试删除id为【"+ id+"】的相册";
        log.debug(message);
        return message;
    }

}
